//
//  PosterSecondCell.m
//  IComic_Stone
//
//  Created by 琳琳 on 15-3-23.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "PosterSecondCell.h"
#import "Poster2CollectionViewCell.h"
@implementation PosterSecondCell
- (void)dealloc
{
    [_posterCollectionView release];
    [_flowLayout release];
    [_posterArr release];
    [_posterNameLabel release];
    [_moreLabel release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        //标题名
        self.posterNameLabel = [[UILabel alloc] init];
        //self.posterNameLabel.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:self.posterNameLabel];
        [_posterNameLabel release];
        //更多
        self.moreLabel = [[UILabel alloc] init];
        //self.moreLabel.backgroundColor = [UIColor yellowColor];
        [self.contentView addSubview:self.moreLabel];
        [_moreLabel release];
        
        self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
        self.flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
        self.flowLayout.minimumLineSpacing = 20;
        self.flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
        
        self.posterCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) collectionViewLayout:self.flowLayout];
        [_flowLayout release];
        self.posterCollectionView.delegate = self;
        self.posterCollectionView.dataSource = self;
        //关闭显示的滚动条
        self.posterCollectionView.showsHorizontalScrollIndicator = NO;
        //按页数翻
        self.posterCollectionView.pagingEnabled = YES;
        //圆角
        self.posterCollectionView.layer.cornerRadius = 20;
        self.posterCollectionView.backgroundColor = [UIColor cyanColor];
        [self.contentView addSubview:self.posterCollectionView];
        [_posterCollectionView release];
        
        [self.posterCollectionView registerClass:[Poster2CollectionViewCell class] forCellWithReuseIdentifier:@"reuse3"];

    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat wight = self.contentView.frame.size.width;
    CGFloat height = self.contentView.frame.size.height;
    
    self.posterNameLabel.frame = CGRectMake(0, 0, wight * 4 / 5, height / 5);
    self.posterNameLabel.text = @"i漫画";
    self.moreLabel.frame = CGRectMake(wight * 4 / 5, 0, wight / 5, height / 5);
    self.moreLabel.text = @"更多>>";
    //flowLayout的大小
    self.flowLayout.itemSize = CGSizeMake((self.contentView.frame.size.width - 80) / 2, (self.contentView.frame.size.height - 40));
    //collectionView 的大小
    self.posterCollectionView.frame = CGRectMake(20, 10 + height / 5, wight - 40, height - 20  - height / 5);
    
}
//cell的数量
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 10;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    Poster2CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse3" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    return cell;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
